package Leetcode;

public class problem203 {

    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    public static ListNode removeElements(ListNode head, int val) {
        ListNode pre = null;
        ListNode cur = head;

        while(cur != null){
            if(cur.val == val){
                if(pre != null){
                    pre.next = cur.next;
                }else{
                    head = head.next;
                }
            }
            pre = cur;
            cur = cur.next;
        }

        return head;

    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(1);
        removeElements(head,1);
    }

}
